import urllib.request

import urllib.parse
import urllib.error
import socket

response = urllib.request.urlopen("https://www.python.org")
print(type(response))
print(response.status)
print(response.getheaders())
print(response.getheader("Server"))

data = bytes(urllib.parse.urlencode({'world': "hello"}), encoding='utf8')
response = urllib.request.urlopen("http://httpbin.org/post", data=data)
print(response.read())
try:
    response = urllib.request.urlopen("http://httpbin.org/get", timeout=0.1)
    print(response.read())

except urllib.error.URLError as e:
    if(isinstance(e.reason, socket.timeout)):
        print('TIME OUT')




